<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style type="text/css">
        .class-title {
            margin-top: 10px;
            margin-left: 10px;
            margin-right: 10px;
            font-size: 20px;
            font-weight: bold;
            color: #00BFFF;
        }

        .class-hr {
            margin-top: 5px;
            height: 1px;
            border: none;
            border-top: 1px solid #DCDCDC;
        }

        .class-seqno {
            margin-top: 3px;
            margin-left: 10px;
            margin-right: 25px;
            font-size: 10px;
            color: #808080;
            font-weight: bold;
            text-align: right;
        }

        .class-table {
            width: 100%;
            text-align: left;
            color: black;
            font-size: 13px;
            margin-left: 2%;
            width: 100%;
            table-layout: fixed;
        }

        .class-td {
            /* white-space: nowrap; */
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            供应商自检文件查看
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">物料编码</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="输入物料编码" id="mrlCode" value="" onclick="getIdSelector();" />
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">批次号</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="输入批次号" id="lotCode" value="" onclick="getIdSelector();" />
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">供应商名称</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="输入供应商名称" id="supplierName" onclick="getIdSelector();">
                    </div>
                </div>
            </li>
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="search()">查询</div>

        <div id="divhtml" style="display: block;width:100%;height: 490px;overflow-y: scroll;"></div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //初始化查询仓库下拉框
    apiready = function() {

        //查询
        //doSearch();
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        $("#" + el.id).select();
    }


    $("#mrlCode").on('keypress', function(e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            //仓库编码
            $("#mrlCode").val(sm);
        }
    });

    function search(){
        //物料编码编码
        var mrlCode = $("#mrlCode").val();
        //工序编码
        var lotCode = $("#lotCode").val();
        //文件名称
        var supplierName = $("#supplierName").val();
        //发货单号非空校验
        if ((mrlCode == "" || mrlCode == null || mrlCode == undefined) && (lotCode == "" || lotCode == null || lotCode == undefined) && (supplierName == "" || supplierName == null || supplierName == undefined)) {
            api.toast({
                msg: "请输入内容后进行查询",
                duration: 3000
            });
            return;
        }
        doSearch();
    }
    //查询
    function doSearch() {
        //物料编码编码
        var mrlCode = $("#mrlCode").val();
        //工序编码
        var lotCode = $("#lotCode").val();
        //文件名称
        var supplierName = $("#supplierName").val();


        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getSupplierDoc";
        var data = {
            values: {
                mrlCode: mrlCode,
                lotCode: lotCode,
                appVersion: api.appVersion,
                supplierName: supplierName,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        //序号
                        html += "<div class='class-seqno'>";
                        html += "<span>" + (i + 1) + "</span>";
                        html += "</div>";
                        //表格
                        html += "<div style='margin-left:10px;margin-right:15px;'>";
                        html += "<table class='class-table'>";
                        // html += "<tr>";
                        // html += "<td class='class-td' style='width:60%'>供应商编码:" + list[i].supplierCode + "</td>";
                        // html += "</tr>";
                        html += "<tr>";
                        html += "<td class='class-td' style='width:80%;word-wrap:break-word;word-break:break-all;'>供应商名称:" + list[i].supplierName + "</td>";
                        html += "</tr>";
                        html += "<tr>";
                        html += "<td class='class-td' >物料编码:" + list[i].mrlCode + "</td>";
                        html += "</tr>";
                        html += "<tr>";
                        html += "<td class='class-td'>物料名称:" + list[i].mrlName + "</td>";
                        html += "</tr>";
                        html += "<tr>";
                        html += "<td class='class-td'>批次号:" + list[i].lotCode + "</td>";
                        html += "</tr>";
                        html += "<tr>";
                        html += "<td class='class-td' >文件名称:" + list[i].fileName + "</td>";
                        html += "<td class='class-td'><div class='aui-btn aui-btn-info' onclick='openFile(\"" + list[i].sysid + "\",\"" + list[i].fileName + "\")'>预览</div></td>";
                        html += "</tr>";
                        html += "</table>";
                        html += "<hr class='class-hr' />";
                        html += "</div>";
                    }
                    $api.html($api.byId("divhtml"), html);

                    //失败
                } else if (myobj.code == "1") {

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //文件预览
    function openFile(docId, fileName) {
        var serverUrl = localStorage.getItem('serverUrl');
        var downloadUrl = serverUrl + `/app/openFile/` + docId;
        api.download({
            url: downloadUrl,
            report: true,
            savePath: 'fs://' + fileName,
        }, function(ret, err) {
            if (ret && 1 == ret.state) { /* 下载完成 */
                // console.log("下载成功savePath:" + ret.savePath);

                // 打开文件
                var docReader = api.require('docReader');
                docReader.open({
                    path: 'fs://' + fileName
                }, function(ret, err) {
                    if (ret.status) {
                        console.log("文件打开成功：" + ret);
                    } else {
                        alert(JSON.stringify(err));
                    }
                });
            }

            if (ret && 2 == ret.state) {
                console.log("下载失败");
            }
        });
    }

    //订单返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
